package top.jacktgq.proxy.jdk.invoke;

import sun.reflect.MethodAccessor;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class TestMethodInvoke {
    public static void main(String[] args) throws Exception {
        Method foo = TestMethodInvoke.class.getMethod("foo", int.class);
        for (int i = 0; i < 17; i++) {
            show(i, foo);
            foo.invoke(null, i);
        }
    }

    // 方法反射调用时，底层MethodAccessor的实现类
    private static void show(int i, Method show) throws Exception {
        Field field = Method.class.getDeclaredField("methodAccessor");
        field.setAccessible(true);
        MethodAccessor methodAccessor = (MethodAccessor) field.get(show);
        System.out.println(i + ":" + methodAccessor);
    }

    public static void foo(int i) {
        System.out.println(i + ":" + "foo");
    }
}
